/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*
*	Julio Montes e-mail: imc.coder@gmail.com
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#define ID_OK 1023
#define ID_CANCEL 2222
#include "alliance/include/FileSelector.h"

namespace alliance
{

FileSelector::FileSelector( const wxString& title, wxArrayString arr,wxString path_file,wxString labelFileOut,
                            int typeFile, string &fIn, string &fOut, wxString &path_wx)
    : wxDialog(NULL,wxID_ANY,title,wxDefaultPosition,wxSize( 320,250 ) )
{

    Connect(ID_OK,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(FileSelector::OnOk));
    Connect(ID_CANCEL,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(FileSelector::OnCancel));


    m_inputFile=&fIn;
    m_outputFile=&fOut;
    p_fo=&path_wx;
    p_file=path_file;
    wxPanel *Panel=new wxPanel( this );

    if(typeFile==1)
    {
        m_instruction=new wxStaticText(Panel,wxID_ANY,wxT("Input Output Conector placement description\n                        Select File "),wxPoint(10,10),wxDefaultSize);
    }
    else
    {
        m_instruction=new wxStaticText(Panel,wxID_ANY,wxT("Creat Pattern file "),wxPoint(90,20),wxDefaultSize);
    }

    m_filesChoose=new wxComboBox(Panel,wxID_ANY,arr[0],wxPoint(50,60), wxSize(200,30),arr,wxCB_READONLY);
    m_instruction2=new wxStaticText(Panel,wxID_ANY,labelFileOut,wxPoint(10,110),wxDefaultSize);
    m_fieldNameFileOut=new wxTextCtrl(Panel,wxID_ANY,wxT(""),wxPoint(50,140),wxSize(200,30));
    m_buttonOk=new wxButton(Panel,ID_OK, wxT("Ok"),wxPoint(160,190));
    m_buttonCancel=new wxButton(Panel,ID_CANCEL, wxT("Cancel"),wxPoint(50,190));
}


void FileSelector::OnOk( wxCommandEvent& event )
{
    wxString l_fn=p_file+m_filesChoose->GetValue();
    wxString l_fnO=p_file+m_fieldNameFileOut->GetValue();
    *p_fo=l_fnO;
    *m_inputFile=string(l_fn.mb_str());
    *m_outputFile=string(l_fnO.mb_str());

    if(!wxFileExists(l_fn))
    {
        wxMessageBox(wxT("Error"));
        EndModal(-1);
    }


    else if(m_fieldNameFileOut->GetValue().IsEmpty())
    {
        wxMessageBox(wxT("Error Name File Out"));
        EndModal(-1);
    }

    EndModal(wxID_OK );
}

void FileSelector::OnCancel(wxCommandEvent& event)
{
    EndModal(wxID_OK );
}


FileSelector::~FileSelector()
{

}

}



